package com.quanyan.user.service.impl;

import com.quanyan.common.constants.Constants;
import com.quanyan.user.mapper.TbUserBlacklistMapper;
import com.quanyan.user.model.db.TbUserBlacklist;
import com.quanyan.user.model.db.TbUserBlacklistExample;
import com.quanyan.user.service.UserBlacklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhang on 16/11/9.
 */
@Service
public class UserBlacklistServiceImpl implements UserBlacklistService {

    @Autowired
    private TbUserBlacklistMapper userBlacklistMapper;

    /**
     * 查询用户是否在黑名单
     * @param uid
     * @param blackId
     * @return
     */
    @Override
    public TbUserBlacklist getUserIsBlack(Integer uid, Integer blackId) {
        List<TbUserBlacklist> userBlacklistList = getUserBlackList(uid,blackId);
        if (userBlacklistList.isEmpty()) {
            return null;
        } else {
            return userBlacklistList.get(0);
        }
    }

    public List<TbUserBlacklist> getUserBlackList(Integer uid,Integer blackId){
        TbUserBlacklistExample example = new TbUserBlacklistExample();
        TbUserBlacklistExample.Criteria criteria = example.createCriteria();
        if (null != uid) {
            criteria.andUidEqualTo(uid);
        }
        if (null != blackId) {
            criteria.andBlackIdEqualTo(blackId);
        }
        criteria.andStateEqualTo(Constants.BYTE_ZERO);
        List<TbUserBlacklist> userBlacklistList = userBlacklistMapper.selectByExample(example);
        return userBlacklistList;
    }

}
